package com.goa.core;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
import lombok.extern.slf4j.Slf4j;

import java.nio.charset.StandardCharsets;

@Slf4j
public class HexEncoder extends MessageToByteEncoder<ByteBuf> {
    @Override
    protected void encode(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) throws Exception {
        // 将 ByteBuf 转换为 16 进制字符串
        log.info("16进制解码器");
        String hexString = ByteBufUtil.hexDump(msg);
        System.out.println("hexString = " + hexString);
        out.writeBytes(hexString.getBytes(StandardCharsets.UTF_8));

    }
}
